{include file="public/header"}
<title>订单录入</title>
</head>
<body>
<style>
</style>

<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-member-add">
        <input type="hidden" name="capital_id" value="{$data['capital_id']}">
        <input type="hidden" name="order_id" value="{$data['ordesr_id']}">
        <input type="hidden" name="type" value="{$type}">
        
        <div class="ch-row ch-info-form">
            <p class="flex1">产品分类：</p>
            <div class="flex2">
                <select class="chan form-control" name="chan">
                    <option value="0" <?php if($data["fen"]==0){?> selected="selected" <?php }?>>套餐</option>
                    <option value="1" <?php if($data["fen"]==1){?> selected="selected" <?php }?>>维修与安装</option>
                    <option value="2" <?php if($data["fen"]==2){?> selected="selected" <?php }?>>其他</option>
                </select>
            </div>
        </div>
        <div class="cp">

        </div>
        <div class="ch-row ch-info-form cdcd">
            <p class="flex1">单价：</p>
            <div class="flex2 ch-row ch-info-form-price">
                <span>$</span>
                <input type="text" class="dan1" name="un_Price" readonly="readonly" value="{$data['un_Price']}">
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1">方量：</p>
            <div class="flex2 ch-row ch-info-form-price">
                <input type="text" name="square" class="fang" style="width: 55%" value="{$data['square']}">
                <input type="text" readonly="readonly" name="company" class="companys" style="width: 15%; border-left: 1px solid #ddd; text-align: right;" value="{$data['company']}" >
                <span style="width: 30%; border: none; padding-left: 5px;"> / 单位</span>
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1">质保：</p>
            <div class="flex2 ch-row">
                <input type="radio" value="0" name="zhi" class="zhi" <?php if($data["zhi"]==0){?> checked="checked" <?php }?>>
                <span style="margin: 0 20px 0 5px;">否</span>
                <input type="radio" value="1" name="zhi" class="zhi" <?php if($data["zhi"]==1){?> checked="checked" <?php }?>>
                <span style="margin: 0 20px 0 5px;">是</span>
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1">总价：</p>
            <div class="flex2 ch-row ch-info-form-price">
                <span>$</span>
                <input type="text" class="jia"  name="to_prices" readonly="readonly" value="{$data['to_price']}">
                <!-- <span class="input-group-addon">.00</span> -->
            </div>
        </div>

        <div class="ch-row ch-info-form">
            <button class="btn btn-primary radius" type="button"><i
                class="Hui-iconfont">&#xe632;</i> 提交
            </button>
        </div>
    </form>
</article>
{include file="public/footer"}
<script>
    s();
    $('.chan').bind("change", function () {
        $('.shan').remove();
        s();
    });
    function s(){
        var cha = $(".chan option:selected").val();
        if (cha == 0) {
            var html =`
                <div class="ch-row ch-info-form shan">
                    <p class="flex1">套餐选择：</p>
                    <div class="flex2">
                        <select name="class_a" class="class_a2 form-control">
                            {volist name="gs" id="v"}
                            <option value="{$v.product_id}"  <?php if($data["class_a"]==$v["product_title"]){?> selected="selected" <?php }?>>{$v.product_title}</option>\n
                            {/volist}
                        </select>
                        <select name="class_b" class="class_b form-control">
                            {volist name="gs1" id="v"}
                            <option value="{$v.product_id}"  <?php if($data["class_b"]==$v["product_title"]){?> selected="selected" <?php }?>>{$v.product_title}</option>\n
                            {/volist}
                        </select>
                    </div>
                </div>`
            $(".cp").append(html);
            $('.cdcd').css('visibility','visible');
        } else if (cha == 1) {

            var html = `
                <div class="ch-row ch-info-form shan">
                    <p class="flex1">清单选择：</p>
                    <div class="flex2">
                        <select name="class_a" class="class_a1 form-control">
                            {volist name="po" id="v"}
                            <option value="{$v.detailed_id}" <?php if($data["class_a"]==$v["detailed_title"]){?> selected="selected" <?php }?>>{$v.detailed_title}</option>\n
                            {/volist}
                        </select>
                        <select name="class_b" class="class_b1 form-control">
                            {volist name="po1" id="v"}
                            <option value="{$v.detailed_id}" <?php if($data["class_b"]==$v["detailed_title"]){?> selected="selected" <?php }?>>{$v.detailed_title}</option>\n
                            {/volist}
                        </select>
                    </div>
                </div>`
            $(".cp").append(html);
            $('.cdcd').css('visibility','visible');
        } else if (cha == 2) {
            var html = `
                <div class="ch-row ch-info-form shan">
                    <p class="flex1">标题：</p>
                    <div class="flex2">
                        <input type="text" name="class_a" placeholder="请输入标题" class=" form-control" value="{$data.class_a}">
                    </div>
                </div>
                <div class="ch-row ch-info-form shan">
                    <p class="flex1">单位：</p>
                    <div class="flex2">
                        <select style="width: 20%;padding: 0.4%;display: inline-block"  name="companys" class="class_a3 form-control">
                        {volist name="g" id="v"}
                        <option value="{$v.title}"<?php if($data["company"]==$v["title"]){?> selected="selected" <?php }?>>{$v.title}</option>\n
                        {/volist}
                        </select>
                    </div>
                </div>
                <div class="ch-row ch-info-form shan">
                    <p class="flex1">标价：</p>
                    <div class="flex2">
                        <input type="number" name="un_Prices" placeholder="请输入标价" class="un_Price form-control" value="{$data.un_Price}">
                    </div>
                </div>
                <div class="ch-row ch-info-form shan">
                    <p class="flex1">备注：</p>
                    <div class="flex2">
                        <textarea name="qi_rmakes" class="form-control">{$data.qi_rmakes}</textarea>
                    </div>
                </div>`
            $(".cp").append(html);
            $('.cdcd').css('visibility','hidden');
            $('.ll').remove();
            $('.o').remove();
            $('.fang').val('');
            $('.jias').val('');
            $('.jia').val('');
        }
    }
    $(document).on("change", ".class_a1", function () {
        var detaileds_id = $(this).val();
        console.log(detaileds_id);
        $.post("{:url('index/order/detailed')}", {detaileds_id: detaileds_id}, function (data, textStatus, xhr) {
            var html;
            var artificial;
            var dan;
            var pris;
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    html += "<option value='" + data[i]['detailed_id'] + "' >" + data[i]['detailed_title'] + "</option>";
                    artificial = data[0]['artificial'];
                    dan = data[0]['titles'];
                    pris = data[0]['rmakes'];
                }
            } else {
                html += "<option value=''>暂无数据</option>";
            }
            $('.class_b1').html(html);
            $('.dan1').val(artificial);
            $('.companys').val(dan);
            $('#price_rule').html(pris);
            $('.fang').val('');
            $('.jias').val('');
            $('.jia').val('');

        });
    });
    $(document).on("change", ".class_a2", function () {
        var product_id = $(this).val();
        console.log(product_id);
        $.post("{:url('index/order/product_chan')}", {product_id: product_id}, function (data, textStatus, xhr) {
            var html;
            var artificial;
            var dan;
            var price_rule;
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    html += "<option value='" + data[i]['product_id'] + "' >" + data[i]['product_title'] + "</option>";
                    artificial = data[0]['prices'];
                    price_rule = data[0]['price_rules'];
                    dan = data[0]['titles'];
                }

            } else {
                html += "<option value=''>暂无数据</option>";

            }
            $('.companys').val(dan);
            $('.class_b').html(html);
            $('.dan1').val(artificial);
            $('#price_rule').html(price_rule);
            $('.fang').val('');
            $('.jias').val('');
            $('.jia').val('');

        });


    });
    $(document).on("change", ".class_b", function () {
        var product_id = $(this).val();
        console.log(product_id);
        $.post("{:url('index/order/product_chan_dan')}", {product_id: product_id}, function (data, textStatus, xhr) {
            var artificial;
            var dan;
            var price_rule;
            artificial = data['prices'];
            dan = data['titles'];
            price_rule = data['price_rules'];
            $('.companys').val(dan);
            $('#price_rule').html(price_rule);

            $('.dan1').val(artificial);
            $('.fang').val('');
            $('.jias').val('');
            $('.jia').val('');

        });


    });
    $(document).on("change", ".class_b1", function () {
        var product_id = $(this).val();
        console.log(product_id);
        $.post("{:url('index/order/detailed_dan')}", {detaileds_id: product_id}, function (data, textStatus, xhr) {
            var artificial;
            var dan;
            var pris;
            artificial = data['artificial'];
            dan = data['titles'];
            pris = data['rmakes'];
            $('#price_rule').html(pris);
            $('.companys').val(dan);
            $('.dan1').val(artificial);
            $('.fang').val('');
            $('.jias').val('');
            $('.jia').val('');

        });


    });

    $('.fang').bind("change", function () {
        console.log(11);
        //向input输入框中赋值
        var chan = $('.chan').val();
        var type = $('.type').val();
        var companys = $('.dan1').val();
        var fang = $('.fang').val();
        var give_money = $('.give_money').val();
        if (chan == 2) {
            if (give_money == undefined)
            {
                give_money=0;
            }
            var un_Price = $('.un_Price').val();

            $('.jia').val((((un_Price * 1000) * fang) / 1000 - give_money).toFixed(2));
            $('.jias').val((((un_Price * 1000) * fang) / 1000).toFixed(2));
        } else {
            if(type==1){
                $('.jia').val((((companys * 1000) * fang) / 1000- give_money).toFixed(2));
                $('.jias').val((((companys * 1000) * fang) / 1000).toFixed(2));
            }else {
                $('.jia').val((((companys * 1000) * fang) / 1000).toFixed(2));
                $('.jias').val((((companys * 1000) * fang) / 1000).toFixed(2));
            }

        }


    });
    $('.un_Price').bind("change", function () {
        //向input输入框中赋值
        $('.fang').val('');
        $('.jias').val('');
        $('.jia').val('');
    });


    /***
     *
     *
     * 提交代码
     * */
    $('.radius').click(function () {
        var src = "{:Url('index/order/edit1')}";
        $.ajax({
            type: 'POST',
            url: src,
            dataType: 'json',
            data: $('form').serializeArray(),
            success: function (data) {
                var res = JSON.parse(data);
                if (res.code == 200) {
                    layer.msg(res.msg, {icon: 1, time: 2000}, function (index, layero) {
                        setTimeout("window.parent.location.reload()", 1);

                    });
                } else {
                    layer.msg(res.msg, {icon: 5, time: 1000});
                }

            },
            error: function (data) {
                console.log(data.msg);
            },
        });

    });

    /**
     * 赠送项目
     *
     **/
    $(".give_a").bind("change", function () {
        give_b();
    });

    function give_b() //市
    {
        var parent_ids = $(".give_a").find("option:selected").val(); //省id
        console.log(parent_ids);
        $.post("{:url('index/order/detailed')}", {detaileds_id: parent_ids}, function (data, textStatus, xhr) {
            var html;
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    html += "<option value='" + data[i]['detailed_id'] + "'>" + data[i]['detailed_title'] + "</option>";
                }

            } else {
                html += "<option value=''>暂无数据</option>";
            }
            $('.give_b').html(html);
        });
    }





    /***
     * 图片上传
     */
    $("#img-change").click(function () {
        $("#file").click();
    });

    function delParent(object) {
        $(object).parent().remove();
        count -= 1;
    }

    var count = 1;
    $(function () {
        var $list = $("#fileList");
        var uploader = WebUploader.create({
            auto: true,
            // 文件接收服务端。
            server: "{:Url('index/upload/upload_file')}",

            // 选择文件的按钮。可选。
            pick: '#filePicker',

            // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
            resize: false,
            duplicate: true,
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/*'
            },
        });

        // 当有文件添加进来的时候
        uploader.on('fileQueued', function (file) {
            var $li = $(
                '<div id="' + file.id + '" class="file-item thumbnail">' +
                '<div onclick="delParent(this)" style="cursor: pointer;background: url({$Think.DOMAIN_SRC}/static/h-ui/images/del.png) no-repeat;background-size:contain;height: 20px;width: 20px;position: absolute;z-index: 10;right: 5px;"></div>' +
                '<img style="width: 100px;height: 100px;">' +
                '<input name="logo[]" type="hidden" value="" class="logo">' +
                '<div class="info">' + file.name + '</div>' +
                '</div>'
                ),
                $img = $li.find('img');

            // $list为容器jQuery实例
            $list.append($li);


            // 创建缩略图
            // 如果为非图片文件，可以不用调用此方法。
            // thumbnailWidth x thumbnailHeight 为 100 x 100
            uploader.makeThumb(file, function (error, src) {
                if (error) {
                    $img.replaceWith('<span>不能预览</span>');
                    return;
                }

                $img.attr('src', src);
            }, 100, 100);
        });


        // 文件上传过程中创建进度条实时显示。
        uploader.on('uploadProgress', function (file, percentage) {
            var $li = $('#' + file.id),
                $percent = $li.find('.progress span');

            // 避免重复创建
            if (!$percent.length) {
                $percent = $('<p class="progress"><span></span></p>')
                    .appendTo($li)
                    .find('span');
            }


            $percent.css('width', percentage * 100 + '%');
        });
        var s = [];
        // 文件上传成功，给item添加成功class, 用样式标记上传成功。
        uploader.on('uploadSuccess', function (file, res) {
            var data = JSON.parse(res._raw);
            if (data.errcode == 300) {
                layer.alert(data.msg);
            }
            var url = data.data;
            count += 1;
            $('#' + file.id).find("logo").attr("src", url);
            $('#' + file.id).find("input").val(url);
            $('#' + file.id).addClass('upload-state-done');
        });

        // 文件上传失败，显示上传出错。
        uploader.on('uploadError', function (file) {
            var $li = $('#' + file.id),
                $error = $li.find('div.error');

            // 避免重复创建
            if (!$error.length) {
                $error = $('<div class="error"></div>').appendTo($li);
            }

            $error.text('上传失败');
        });

        // 完成上传完了，成功或者失败，先删除进度条。
        uploader.on('uploadComplete', function (file) {
            $('#' + file.id).find('.progress').remove();
        });
    });

</script>
</body>
</html>